#!/bin/bash

# 环境变量示例
##export ENV=dev
##export PLATFORM=linkapp
##export SERVICE_COMPONENT=backend
##export ACTION=restart

# 环境
ENV="${ENV:-unknown}"
# 平台
PLATFORM="${PLATFORM:-unknown}"
# 服务组件
SERVICE_COMPONENT="${SERVICE_COMPONENT:-unknown}"
# 应用标识
APP_MARK="${PLATFORM}-${SERVICE_COMPONENT}_4_${ENV}"
# 守护进程名
SERVICE_NAME="springboot-${APP_MARK}"
# 服务动作（默认为重启）
ACTION="${ACTION:-restart}"

if [ $ENV == "unknown" -o $PLATFORM == "unknown" -o $SERVICE_COMPONENT == "unknown" ]; then
    echo "Warnings: 必填参数 ENV, PLATFORM, SERVICE_COMPONENT 丢失。"
    exit 1
fi

systemctl ${ACTION} ${SERVICE_NAME}
